package com.dhl.fin.api.service;

import cn.hutool.core.date.DateUtil;
import com.dhl.fin.api.domain.RemindTask;
import com.dhl.fin.api.enums.RemindDateTypeEnum;
import com.dhl.fin.api.service.cronService.RemindCron;
import com.dhl.fin.api.util.SolarDateUtil;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * @author CuiJianbo
 * @since 2025/5/5
 */
@Service
public class OneTimesCron implements RemindCron {

    @Override
    public String calculateCron(RemindTask remindTask) {
        Date remindDate = remindTask.getRemindDate();
        String[] remindTime = remindTask.getRemindTime().split(":");
        int month = DateUtil.month(remindDate) + 1;
        int days = DateUtil.dayOfMonth(remindDate);

        if (remindTask.getDateType().equals(RemindDateTypeEnum.SOLAR.getName())) {
            //按照农历获取公历日期
            Date dateTime = SolarDateUtil.getSolarDate(remindTask);
            month = DateUtil.month(dateTime) + 1;
            days = DateUtil.dayOfMonth(dateTime);
        }

        return String.format("0 %s %s %d %d ?", remindTime[1], remindTime[0], days, month);
    }

}



